package item7_02.src.com.company.section2;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

public class Client {
	public static void main(String[] args) {
		Foo<List<String>> list = new Foo<List<String>>(ArrayList.class.getName());
		
		//编译不通过
		//List<String> [] array = new List<String>[];
		
		List<String>[] gettArray = list.gettArray();
		gettArray[0] = new ArrayList<String>(){
			{
				add("1");
				add("2");
			}
		};
		System.out.println(gettArray[0].size());
		
	}
}

class Foo<T>{
	//不再初始化，由构造函数初始化
	private T t;
	private T[] tArray;
	//private List<T> list= new ArrayList<T>();
	//构造函数初始化
	public Foo(String className){
		try {
			Class<?> tType = Class.forName(className);
			t = (T)tType.newInstance();
			tArray = (T[])Array.newInstance(tType,5);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public T[] gettArray() {
		return tArray;
	}
	public void settArray(T[] tArray) {
		this.tArray = tArray;
	}
	
	
}
